package ru.mcfr.oxygen.framework.listeners;

import ro.sync.ecss.extensions.api.AuthorAccess;
import ro.sync.ecss.extensions.api.AuthorCaretEvent;
import ro.sync.ecss.extensions.api.AuthorCaretListener;
import ru.mcfr.oxygen.framework.ui.MOFPopupWindow;

public class MOFAuthorCaretListener implements AuthorCaretListener {

    private AuthorAccess authorAcess;

    private MOFPopupWindow popupWindow;

    public MOFAuthorCaretListener(AuthorAccess authorAccess) {
//    this.authorAcess = authorAccess;
//    // Use the information popup only if this is the standalone Oxygen version.
//    if (authorAccess.isStandalone()) {
//      // Create the information popup window.
//      popupWindow = new SDFPopupWindow(authorAccess, "XML Fragment:");
//    } 
    }

    public void caretMoved(AuthorCaretEvent caretEvent) {



        // Verify if the node corresponding to the new caret position corresponds to a "para" element.
//    if (authorAcess.isStandalone()) { 
//      int caretOffset = authorAcess.getEditorAccess().getCaretOffset();
//      try {
//        AuthorNode nodeAtOffset = authorAcess.getDocumentController().getNodeAtOffset(caretOffset);
//        if (nodeAtOffset != null && nodeAtOffset instanceof AuthorElement) {
//          AuthorElement element = (AuthorElement) nodeAtOffset;
//          if ("para".equals(element.getLocalName())) {
//            AuthorDocumentFragment paraFragment = authorAcess.getDocumentController().createDocumentFragment(element, true);
//            String serializeFragmentToXML = authorAcess.getDocumentController().serializeFragmentToXML(paraFragment);
//            // Find the x and y coordinates from the caret shape  (the popup window location).
//            int[] modelToView = authorAcess.getEditorAccess().modelToView(authorAcess.getCaretOffset());
//            popupWindow.setTimeToDisplay(3);
//            popupWindow.display(serializeFragmentToXML, modelToView[0], modelToView[1], 10);
//          }
//        }
//      } catch (BadLocationException e) {
//      }
//    }
    }
}
